package utilclasses;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

/**
 * 
 * @author egmweb & keaneb1
 */
public class Validator {

    /**
     * 
     * @param emailAddress
     * This method will validate whether the emailAddress entered by the Staff Agent is correct.
     * @return False if not correct, otherwise return true.
     */
    public boolean isValidEmailAddress(String emailAddress) {
        String expression = "^[\\w\\-]([\\.\\w])+[\\w]+@([\\w\\-]+\\.)+[A-Z]{2,4}$";
        CharSequence inputStr = emailAddress;
        Pattern pattern = Pattern.compile(expression, Pattern.CASE_INSENSITIVE);
        Matcher matcher = pattern.matcher(inputStr);
        return matcher.matches();
    }
    /**
     * 
     * This method will validate whether the Credit Card number has 16 digits in length. Letter not permitted.
     * @return False if not correct, otherwise return true.
     */
    public boolean isValidCreditCard(String ccNumber){
        Pattern pattern = Pattern.compile("\\d{16}");
        Matcher matcher = pattern.matcher(ccNumber);
        if (matcher.matches()) {
            return true;
        }else{
            return false;
        }
    }
    /**
     * 
     * This method will validate whether the license has 10 digits in length. Letters are not accepted.
     * @return False if not correct, otherwise return true.
     */
    public boolean isValidLicense(String ccNumber){
        Pattern pattern = Pattern.compile("\\d{10}");
        Matcher matcher = pattern.matcher(ccNumber);
        if (matcher.matches()) {
            return true;
        }else{
            return false;
        }
    }    
    /**
     * 
     * This method will validate whether the CVS code has 3 digits in length. No letters are allowed.
     * @return False if not correct, otherwise return true.
     */
    public boolean isValidCodeCreditCard(String ccNumber){
        Pattern pattern = Pattern.compile("\\d{3}");
        Matcher matcher = pattern.matcher(ccNumber);
        if (matcher.matches()) {
            return true;
        }else{
            return false;
        }
    }
    /**
     * 
     * This method will validate whether the Customer First name is correct. It can be lowercase or uppercase or mixed.
     * @return False if not correct, otherwise return true.
     */
    public boolean isValidString(String string){
        Pattern pattern = Pattern.compile("[A-Za-z]+[a-zA-Z]*");
        Matcher matcher = pattern.matcher(string);
        if (matcher.matches()) {
            return true;
        }else{
            return false;
        }
    }
    /**
     * 
     * This method will validate whether the Full Name of the Customer is valid. No numbers are allowed.
     * @return False if not correct, otherwise return true.
     */
    public boolean isValidFullName(String string){
        Pattern pattern = Pattern.compile("[a-z A-Z]*");
        Matcher matcher = pattern.matcher(string);
        if (matcher.matches()) {
            return true;
        }else{
            return false;
        }
    }
    /**
     * 
     * This method will validate that only numbers are entered when searching for the Credit Card to retrieve the Customer details.
     * @return False if not correct, otherwise return true.
     */
    public boolean isOnlyNumbers(String string){
        Pattern pattern = Pattern.compile("[a-z A-Z]*");
        Matcher matcher = pattern.matcher(string);
        if (matcher.matches()) {
            return false;
        }else{
            return true;
        }
    } 
}